package com.abvnet.project.water.project.controller;

import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.water.project.domain.ProjectCustomerContact;
import com.abvnet.project.water.project.service.IProjectCustomerContactService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户联系信息操作处理
 * 
 * @author duj
 * @date 2019-08-17
 */
@Controller
@RequestMapping("/project/projectCustomerContact")
public class ProjectCustomerContactController extends BaseController {
    private String prefix = "project/projectCustomerContact";
	
	@Autowired
	private IProjectCustomerContactService projectCustomerContactService;
	
	@RequiresPermissions("project:projectCustomerContact:view")
	@GetMapping()
	public String projectCustomerContact()
	{
	    return prefix + "/list";
	}
	
	/**
	 * 查询客户联系列表
	 */
	@RequiresPermissions("project:projectCustomerContact:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProjectCustomerContact projectCustomerContact) {
		startPage();
        List<ProjectCustomerContact> list = projectCustomerContactService.selectProjectCustomerContactList(projectCustomerContact);
		return getDataTable(list);
	}
	
	/**
	 * 新增客户联系
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客户联系
	 */
	@RequiresPermissions("project:projectCustomerContact:add")
	@Log(title = "客户联系", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProjectCustomerContact projectCustomerContact) {
		return toAjax(projectCustomerContactService.insertProjectCustomerContact(projectCustomerContact));
	}

	/**
	 * 修改客户联系
	 */
	@GetMapping("/edit/{contactId}")
	public String edit(@PathVariable("contactId") Long contactId, ModelMap mmap) {
		ProjectCustomerContact projectCustomerContact = projectCustomerContactService.selectProjectCustomerContactById(contactId);
		mmap.put("projectCustomerContact", projectCustomerContact);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客户联系
	 */
	@RequiresPermissions("project:projectCustomerContact:edit")
	@Log(title = "客户联系", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProjectCustomerContact projectCustomerContact) {
		return toAjax(projectCustomerContactService.updateProjectCustomerContact(projectCustomerContact));
	}
	
	/**
	 * 删除客户联系
	 */
	@RequiresPermissions("project:projectCustomerContact:remove")
	@Log(title = "客户联系", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(projectCustomerContactService.deleteProjectCustomerContactByIds(ids));
	}
	
}
